package com.just.springbootmessage.rabbitmq;

import com.just.springbootmessage.dao.PersonRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class SendMessageImpl implements SendMessageService{
    private Logger logger=LoggerFactory.getLogger(SendMessageImpl.class);
    @Autowired
    private RabbitTemplate rabbitTemplate;
    @Autowired
    private PersonRepository personRepository;
    @Transactional(rollbackFor = Exception.class)
    public void sendTrans(){
       // Person person=new Person(null,"小娃",11,"世纪大道");
       // personRepository.save(person);
        logger.info("向队列1发送消息");
        rabbitTemplate.convertAndSend(RabbitContent.RABBIT_QUEUE1,"我是不能达到的消息，呦呦");
        throw new IllegalArgumentException("抛异常，期待回滚");
    }
}
